/**
 * 
 */
package com.cdfahe.gms.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Service;

import com.cdfahe.common.util.SQLAdapter;
import com.cdfahe.common.util.SearchCondition;
import com.cdfahe.gms.mybatis.mapper.CommonMapper;
import com.cdfahe.gms.service.ICommonService;

/**
 * 通用服务实现类
 * @author  Roy
 * @version 
 * @since   JDK1.6
 */
@Service
public class CommonServiceImpl implements ICommonService {
	

	
	@Resource
	private CommonMapper commonMapper;

	@Override
	public  List<Map<String, String>> getDataBySql(SQLAdapter sql) {
		return commonMapper.findRecords(sql);
	}

	@Override
	public String getSearchWhereStr(HttpServletRequest request) {
		String where = "";
		String fields = request.getParameter("fields");
		if (fields != null && !"".equals(fields.trim())) {
			String[] field = fields.split(",");
			for (String f : field) {
				String cb = request.getParameter("cb_" + f);
				String operators = request.getParameter("operators_" + f);
				String values = request.getParameter("values_" + f);
				if ("contains".equals(operators)) {
					where += " and " + cb + " like '%" + values + "%'";
				} else if ("not contains".equals(operators)) {
					where += " and " + cb + " not like '%" + values + "%'";
				} else if ("is".equals(operators)) {
					where += " and " + cb + " in (" + values + ")";
				} else if ("is not".equals(operators)) {
					where += " and " + cb + " not in (" + values + ")";
				}
			}
		}
		
		return where;
	}

	@Override
	public void delQueryById(int id) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void updateUsecountById(int id) {
		// TODO Auto-generated method stub
		
	}

	
}
